package com.demo.springboot.controller;

import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.Arrays;
import java.util.Map;

@Controller
public class helloController {
    @ResponseBody
    @RequestMapping("/hello")
    public String hello(){
        return  "hello world";
    }
    @RequestMapping("/success")
    public String seccess(Map<String,Object> map){
        //classpath:/templates/success.html
        map.put("hello","<h1>123456</h1>");
        map.put("users",Arrays.asList("qqq","www","eee","rrr"));
        return "success";
    }

    @RequestMapping("/user/login")
    public String login(String username, String password, Map<String,Object> map, HttpSession session){
        if ("admin".equals(username) && "123456".equals(password)){
            session.setAttribute("user","username");
            return "redirect:/main.html";
        }else{
            map.put("msg","用户名密码错误");
            return "login";
        }


    }
}
